/* 
This do-file prepares recomputing the spillovers by  
- merging the inventor-weighted country weights by firm
- merging the in/outsample counts/multiplier by country
*/


* go to bvd-ctry-year-div level
mmerge firm_division year using ${d}datasets/macrosim/BvD_ctry_year_div_list_${ln_vers}pauto95_${iwvers}${osmtrim}.dta, unmatched(master)
assert _m == 3
drop _m

* merge in pre-sample weight for distribution of spillovers to the firms
mmerge BvD ctry using ${d}datasets/macrosim/bvd_ctry_inventor_weightspre_long.dta, unmatched(master)
ren weight weight_pre
replace weight_pre = 0 if _m == 1
drop _m

*merge in the weights that assign patent shares to the countries (and therefore countrystocks and spillovers) 
mmerge BvD year ctry division using ${d}datasets/macrosim/bvd_ctry_year_inventor_weights${iwvers}_long.dta, unmatched(master)   
ren weight weight_${iwvers}
replace weight_${iwvers} = 0 if _m == 1
drop _m


* merge in counts and the multiplier
mmerge ctry year division using ${d}datasets/macrosim/ctry_year_div_outsamplemultipliers_${ln_vers}pauto95_${chosen_spec}${FE}_${iwvers}${osmtrim}_trimmed.dta, unmatched(master)
assert _m == 3
drop _m

